import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import VitePluginImporter from 'vite-plugin-importer'
import { fetchResolver } from './resolver'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia'],
      resolvers: [fetchResolver()]
    }),
    VitePluginImporter({
      libraryName: 'vant',
      style: true
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  // 代理
  server: {
    proxy: {
      '/api': {
        target: 'https://baobab.kaiyanapp.com',
        changeOrigin: true
        // rewrite: (path) => path.replace(/^\/api/, '')
      },
      '/androidApi': {
        target: 'https://www.wanandroid.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/androidApi/, '')
      }
    }
  }
})
